<? if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Activities_model extends CI_Model
{
	public $num_edge_entries = 2;
	public $items_per_page = 10;

	public function add_activity($data)
	{
		$this->db->insert('activities',$data);
	}

	public function get_activities()
	{
		return $this->db->order_by('activity_created', 'desc')->get('activities');
	}

	public function get_activities_with_idx($idx)
	{
		$offset = $idx * $this->items_per_page;

		return $this->db
			->order_by('activity_created', 'desc')
			->get('activities', $this->items_per_page, $offset);
	}

	// db_check

	public function delete_act_sales($date){
		$this->db->where('date(activity_created) <=',$date)->delete('activities');
		$this->db->where('date(sales_item_created) <=',$date)->delete('sales_items');
		$this->db->where('date(sale_created) <=',$date)->delete('sales');
	}
}